package ui.activity.mine.presenter;


import javax.inject.Inject;

import base.BaseBiz;
import ui.activity.mine.BankCardAct;
import ui.activity.mine.ReturnIncomeAct;
import ui.activity.mine.biz.MyWalletBiz;
import ui.activity.mine.contract.MyWalletContract;
import ui.activity.wallet.RewardsAct;
import ui.model.AccountMoneyInfo;
import ui.model.ItemsInfo;
import ui.model.WithDrawInfo;

/**
 * Created by chenjian on 19/2/26
 */

public class MyWalletPresenter implements MyWalletContract.Presenter {

    MyWalletContract.View view;
    MyWalletBiz myWalletBiz;


    @Inject
    public MyWalletPresenter(MyWalletContract.View view) {
        this.view = view;
    }


    @Override
    public void setBiz(BaseBiz biz) {
        myWalletBiz = (MyWalletBiz) biz;
    }

    @Override
    public void getUserIncome(boolean isRefresh) {
        view.loading(true);
        myWalletBiz.getUserIncome(new BaseBiz.Callback<ItemsInfo<AccountMoneyInfo>>() {
            @Override
            public void onSuccess(ItemsInfo<AccountMoneyInfo> info) {
                view.upDateUI(info.getItems());
                if (isRefresh) {
                    view.refreshComplete();
                } else {
                    view.loadMoreComplete();
                }
                view.loading(false);
                view.hasLoadMore(false);
            }

            @Override
            public void onFailure(ItemsInfo<AccountMoneyInfo> info) {
                if (isRefresh) {
                    view.refreshComplete();
                } else {
                    view.loadMoreComplete();
                }
                view.loading(false);
                view.hasLoadMore(false);
            }
        });
        getWithInfo();
    }

    @Override
    public void toCardList() {
        view.startActString(BankCardAct.class, "0");
    }

    @Override
    public void toReturNofincome(String type) {
        view.startActString(ReturnIncomeAct.class, type);
    }

    @Override
    public void toScore() {
    }

    @Override
    public void getWithInfo() {
        myWalletBiz.getWithDrawInfo(new BaseBiz.Callback<WithDrawInfo>() {
            @Override
            public void onSuccess(WithDrawInfo info) {
                view.upDateInfo(info);
            }

            @Override
            public void onFailure(WithDrawInfo info) {

            }
        });
    }

    @Override
    public void toRewards() {
        view.startAct(RewardsAct.class,null);
    }
}
